﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Small.Html.Options
{
    public abstract class JqGridColModelFormatter:JqBase
    {
        private  string format;


        protected JqGridColModelFormatter() 
        {
        
        
        }
        public JqGridColModelFormatter(string format) 
        {
          
            this.format = string.Format("formatter:'{0}'",format);
        }

        public abstract string GenerateFormatterString();


        public override string GenerateString()
        {
            return null;
        }


        protected string FormatString(List<String> list)
        {
            string formatOptions = string.Empty;
            if (list.Count > 0)
            {
                formatOptions = "formatoptions:{" + string.Join(",", list.ToArray()) + "}";

            }
            if (!String.IsNullOrEmpty(formatOptions))
            {
                return format + "," + formatOptions;
            }
            return null;
        }

       
    }


    public class JqGridCurrencyFormat : JqGridColModelFormatter
    {


        List<String> list = new List<string>();
        public JqGridCurrencyFormat()
            : base("currency") 
        {
         
        }
      
        private string decimalSeparator;

        /// <summary>
        /// 小数点分隔符
        /// </summary>
        public string DecimalSeparator
        {
            get { return decimalSeparator; }
            set { decimalSeparator = value;
            list.Add(IsStringNull("decimalSeparator", decimalSeparator));
            }
        }
        private string thousandsSeparator;

        /// <summary>
        /// 千分比分隔符
        /// </summary>
        public string ThousandsSeparator
        {
            get { return thousandsSeparator; }
            set { thousandsSeparator = value;
             list.Add(IsStringNull("thousandsSeparator", thousandsSeparator));
            }
        }
        private int decimalPlaces;

        /// <summary>
        /// 保留小数点
        /// </summary>
        public Int32 DecimalPlaces
        {
            get { return decimalPlaces; }
            set { decimalPlaces = value;
              list.Add(IsInteger("decimalPlaces", decimalPlaces));
            }
        }
        private decimal defaulValue;

        /// <summary>
        /// 默认值
        /// </summary>
        public decimal DefaulValue
        {
            get { return defaulValue; }
            set { defaulValue = value;
            
             list.Add(IsDecimal("defaulValue", defaulValue));}
        }
        private string prefix;

        /// <summary>
        /// 前缀
        /// </summary>
        public string Prefix
        {
            get { return prefix; }
            set { prefix = value;
             list.Add(IsStringNull("prefix", prefix));
            }
        }
        private string suffix;

        public string Suffix
        {
            get { return suffix; }
            set { suffix = value;
             list.Add(IsStringNull("suffix", suffix));
            }
        }
       
            


        public override string GenerateFormatterString()
        {
            
            return FormatString(list);
          
        }

       

    }

    public class JqGridNumberFormat : JqGridColModelFormatter
    {


        
        List<String> list = new List<string>();
            
            
            
            
        public JqGridNumberFormat() : base("number") 
        {
        
        }
       
        private string decimalSeparator;

        public string DecimalSeparator
        {
            get { return decimalSeparator; }
            set { decimalSeparator = value;
            list.Add(IsStringNull("decimalSeparator", decimalSeparator));
            }
        }
        private string thousandsSeparator;

        public string ThousandsSeparator
        {
            get { return thousandsSeparator; }
            set { thousandsSeparator = value;
            list.Add(IsStringNull("thousandsSeparator", thousandsSeparator));
            }
        }
        private int decimalPlaces;

        public int DecimalPlaces
        {
            get { return decimalPlaces; }
            set { decimalPlaces = value;
            list.Add(IsInteger("decimalPlaces", decimalPlaces));
            }
        }
        private decimal defaulValue;

        public decimal DefaulValue
        {
            get { return defaulValue; }
            set { defaulValue = value;
            list.Add(IsDecimal("defaulValue", defaulValue));
            }
        }



        public override string GenerateFormatterString()
        {
            
           
           
            return FormatString(list);
        }
    }


    public class JqGridEmailFormatOptions : JqGridColModelFormatter
    {
    
        public JqGridEmailFormatOptions()
            : base("email") 
        {
        
        }
        public override string GenerateFormatterString()
        {
            List<String> list = new List<string>();

            list = list.Where(p => !String.IsNullOrEmpty(p)).Select(p => p).ToList();
            return FormatString(list);
        }
    }

    public class JqGridLinkColModeFormat : JqGridColModelFormatter
    {
        public JqGridLinkColModeFormat()
            : base("link") 
        {
        
        }
        
            List<String> list = new List<string>();
            
        private string target;

        public string Target
        {
            get { return target; }
            set { target = value;
            list.Add(IsStringNull("target", target));
            }
        }

        public override string GenerateFormatterString()
        {
   
            return FormatString(list);
        }
       
    }

    public class JqGridColModeCheckBoxFromat : JqGridColModelFormatter
    {
        public JqGridColModeCheckBoxFromat()
            : base("checkbox") 
        {
        
        }
        List<String> list = new List<string>();
            
        private bool disabled=false;

        public bool Disabled
        {
            get { return disabled; }
            set { disabled = value;
            list.Add(IsBool("disabled", disabled));
            }
        }
        public override string GenerateFormatterString()
        {
            
    
            return FormatString(list);
        }
       
        
    }

    public class JqGridColModeSelectFormatOptions : JqGridColModelFormatter
    {

        public JqGridColModeSelectFormatOptions()
            : base("select") 
        {
        
        }



        public override string GenerateFormatterString()
        {
            List<String> list = new List<string>();
            list = list.Where(p => !String.IsNullOrEmpty(p)).Select(p => p).ToList();
            return FormatString(list);
        }
    }

    public class JqGridColModeActionsFormat : JqGridColModelFormatter
    {

        public JqGridColModeActionsFormat()
            : base("actions") 
        {
        
        }


        private bool keys=false;//default false,

        public bool Keys
        {
            get { return keys; }
            set { keys = value; list.Add(IsBool("Keys", Keys)); }
        }
        private bool editbutton=true;// default true, 

        public bool Editbutton
        {
            get { return editbutton; }
            set { editbutton = value; list.Add(IsBool("editbutton", editbutton)); }
        }
        private bool delbutton=true;//default true

        public bool Delbutton
        {
            get { return delbutton; }
            set { delbutton = value;list.Add(IsBool("delbutton", delbutton)); }
        }
         List<String> list = new List<string>();
           
           
            



        public override string GenerateFormatterString()
        {
           

         
            return FormatString(list);
        }
    }
    public class JqGridColModeDateFormat : JqGridColModelFormatter
    {
     
        public JqGridColModeDateFormat()
            : base("date") 
        {
        
        }
        private string srcformat;

        public string Srcformat
        {
            get { return srcformat; }
            set { srcformat = value;   list.Add(IsStringNull("srcformat", srcformat)); }
        }
        private string newformat;

        public string Newformat
        {
            get { return newformat; }
            set { newformat = value; list.Add(IsStringNull("newformat", newformat)); }
        }
          List<String> list = new List<string>();
         
            


        public override string GenerateFormatterString()
        {
          
            
         
            return FormatString(list);
        }
    }
    public class JqGridColModeIntegetFormat : JqGridColModelFormatter
    {
     

        public JqGridColModeIntegetFormat()
            : base("integer") 
        {
        
        }

        private string thousandsSeparator;

        public string ThousandsSeparator
        {
            get { return thousandsSeparator; }
            set { thousandsSeparator = value; list.Add(IsStringNull("thousandsSeparator", thousandsSeparator)); }
        }
        private Int32 defaulValue = 0;

        public Int32 DefaulValue
        {
            get { return defaulValue; }
            set { defaulValue = value;list.Add(IsInteger("defaulValue", defaulValue)); }
        }
           List<String> list = new List<string>();
           
            


        public override string GenerateFormatterString()
        {
         

            list = list.Where(p => !String.IsNullOrEmpty(p)).Select(p => p).ToList();
            return FormatString(list);
        }
    }
    //链接格式
    public class JqGridColModeShowLinkFormat : JqGridColModelFormatter
    {
        public JqGridColModeShowLinkFormat()
            : base("showlink") 
        {
        
        }


        private string baseLinkUrl;

        public string BaseLinkUrl
        {
            get { return baseLinkUrl; }
            set { baseLinkUrl = value; list.Add(IsStringNull("baseLinkUrl", baseLinkUrl)); }
        }
        private string addParam;

        public string AddParam
        {
            get { return addParam; }
            set { addParam = value; list.Add(IsStringNull("addParam", addParam)); }
        }
        private string idName;

        public string IdName
        {
            get { return idName; }
            set { idName = value; list.Add(IsStringNull("idName", idName));
            }
        }
        private string showAction;

        public string ShowAction
        {
            get { return showAction; }
            set { showAction = value; list.Add(IsStringNull("showAction", showAction)); }
        }
        private string target;

        public string Target
        {
            get { return target; }
            set { target = value;  list.Add(IsStringNull("target", target));}
        }

         List<String> list = new List<string>();
            
           
           
           
          


        public override string GenerateFormatterString()
        {
           
            return FormatString(list);
        }
    }
}
